package org.budo.canal.parse.util;

import org.budo.support.lang.util.ReflectUtil;

import com.alibaba.otter.canal.parse.CanalEventParser;
import com.alibaba.otter.canal.parse.inbound.AbstractEventParser;
import com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser;
import com.alibaba.otter.canal.parse.support.AuthenticationInfo;
import com.alibaba.otter.canal.sink.CanalEventSink;

/**
 * @author lmw
 */
public class EventParserUtil {
    public static String getDestination(Object eventParser) {
        String destination = (String) ReflectUtil.getFieldValue(AbstractEventParser.class, "destination", eventParser);
        return destination;
    }

    public static AuthenticationInfo getMasterInfo(CanalEventParser eventParser) {
        AuthenticationInfo masterInfo = (AuthenticationInfo) ReflectUtil.getFieldValue(eventParser, "masterInfo");
        return masterInfo;
    }

    public static CanalEventSink getEventSink(CanalEventParser eventParser) {
        CanalEventSink eventSink = (CanalEventSink) ReflectUtil.getFieldValue(eventParser, "eventSink");
        return eventSink;
    }

    public static Long getSlaveId(MysqlEventParser eventParser) {
        Long slaveId = (Long) ReflectUtil.getFieldValue(MysqlEventParser.class, "slaveId", eventParser);
        return slaveId;
    }
}